package com.example.demo.controller;

import com.example.demo.entity.Teacher;
import com.example.demo.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class TeacherController {

    @Autowired
    TeacherService teacherService;

    @PostMapping("/teacher")
    public int save(@RequestBody Teacher teacher){
        return teacherService.save(teacher);
    }

    @DeleteMapping("/teacher/{tid}")
    public int delete(@PathVariable("tid") int tid){
        return teacherService.delete(tid);
    }

    @PutMapping("/teacher")
    public int update(@RequestBody Teacher teacher){
        return teacherService.update(teacher);
    }

    @GetMapping("/teacher")
    public List<Teacher> select(){
        return teacherService.select();
    }

    @PostMapping("/register")
    public int register(@RequestBody Teacher teacher){
        return teacherService.register(teacher);
    }

    @GetMapping("/login")
    public List<Teacher> login(){
        return teacherService.login();
    }
}
